package cn.itsource.blog.service.impl;

import cn.itsource.blog.domain.Employee;
import cn.itsource.blog.mapper.EmployeeMapper;
import cn.itsource.blog.service.IEmployeeService;
import cn.itsource.query.BaseQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public PageInfo<Employee> pageInfo(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getCurrentPage(), baseQuery.getPageSize());
        List<Employee> all = employeeMapper.getAllByQuery(baseQuery);
        return new PageInfo<>(all);
    }

    @Override
    public void save(Employee employee) {
        if (employee.getId() == null) {
            employeeMapper.save(employee);
        }else{
            employeeMapper.update(employee);
        }
    }

    @Override
    public void delete(Long id) {
        employeeMapper.delete(id);
    }

    @Override
    public void batchDelete(List<Employee> users) {
        employeeMapper.batchDelete(users);
    }



}
